package com.bos.dao.repositories;

import com.bos.domian.system.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author misterWei
 * @create 2019年01月01号:20点40分
 * @mailbox mynameisweiyan@gmail.com
 */
public interface MenuRepository extends JpaRepository<Menu,Integer>,JpaSpecificationExecutor<Menu> {
    /**
     * 根据用户ID查找角色,根据角色查找菜单
     * @param id
     * @return
     */
    @Query("from Menu m inner join fetch m.roles r inner join fetch r.users u where u.id = ?1 order by m.description desc ")
    List<Menu> findByUser(Integer id);
}
